﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _08_SumOfArrayOfDigits
{
    class Program
    {
        static void PrintArray(List<int> list)
        {
            list.Reverse();
            foreach (var item in list)
            {
                Console.Write(item);
            }
        }
        static List<int> SumDigits(byte[] firstArray, byte[] secondArray)
        {
            List<int> resultArray = new List<int>();
            int remainder = 0;
            int biggestLength = firstArray.Length < secondArray.Length ? secondArray.Length : firstArray.Length;
            for (int index = 0; index < biggestLength; index++)
            {
                int firstArrayDigit = index < firstArray.Length ? firstArray[index] : 0;
                int secondArrayDigit = index < secondArray.Length ? secondArray[index] : 0;
                int digit = firstArrayDigit + secondArrayDigit + remainder;
                remainder = digit / 10;
                resultArray.Add(digit % 10);
            }
            if (remainder > 0)
            {
                resultArray.Add(remainder);
            }
            return resultArray;
        }
        static void Main()
        {
            byte[] num1 = { 1,6,0, 1,1,1 };
            byte[] num2 = { 2, 4,4 };

            PrintArray(SumDigits(num1, num2));
            Console.WriteLine();
        }
        
    }
}
